﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LumenWorks.Framework.IO.Csv;
using System.Reflection;

namespace Secams.utils
{
    public class CsvUtils
    {

        public static object loadObject(string[] headers, CsvReader csvReader, object obj)
        {
            for(int col = 0; col < headers.Length; col++) {
                PropertyInfo propInfo = obj.GetType().GetProperty(headers[col]);
                if (propInfo == null)
                    throw new KeyNotFoundException("header "+headers[col]+" is not valid");
                Type propType = propInfo.PropertyType;
                propInfo.SetValue(obj, TypeConverter.fromString(propType, csvReader[col]), null);
            }
            return obj;
        }
    }
}
